package sessionHandler

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Charts"
	"go-fox-edge-channel-tcp-server/channelService/reportService"
	"net"
)

type SessionHandler struct {
	ReturnText string
}

func (e *SessionHandler) OnMessage(ctx net.Conn, serviceKey string, data []byte) {
	// 上报数据
	if e.ReturnText == "" {
		// 保存PDU到接收缓存
		reportService.Push(serviceKey, data)
	} else {
		message := ""

		// GB2312编码的字符串，在GO的字符库中标识为GBK
		if "GB2312" == e.ReturnText {
			gb2312, err := Charts.GbkToUtf8Str(data)
			if err != nil {
				return
			}

			message = gb2312
		} else {
			message = string(data)
		}

		reportService.Push(serviceKey, message)
	}
}
